﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.ReportSource;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Windows;

namespace UI.Desktop
{
    public partial class frmReporteTurnos : Form
    {
        public frmReporteTurnos()
        {
            InitializeComponent();
        }

        private void cbProfesional_Click(object sender, EventArgs e)
        {
            Business.Entities.Profesional prof = new Business.Entities.Profesional();
            DataSet dsProf = new DataSet();
            dsProf = prof.ObtenerListaProfesional();
            ObtenerProfesional(dsProf);
        }

        private void ObtenerProfesional(DataSet dsProf)
        {
            cbProfesional.Text = "Seleccione el profesional";
            cbProfesional.DataSource = dsProf.Tables["Profesional"];
            string Id_profesional = dsProf.Tables["Profesional"].Columns[0].Caption.ToString();
            string apellido = dsProf.Tables["Profesional"].Columns[0].Caption.ToString();



            cbProfesional.DisplayMember = apellido;



        }

        private void btnEmitir_Click(object sender, EventArgs e)
        {
            

                ReportDocument rpt = new ReportDocument();
                rpt.Load(@"C:\Users\g\Desktop\Sistema TurNet\Code\turnet_v1.5\UI.Desktop\ReporteTurnos.rpt");
                Business.Entities.Profesional prof = new Business.Entities.Profesional();
                Business.Entities.Turno Entur = new Business.Entities.Turno();
                string Concatenado = cbProfesional.Text;
                DataSet dsProf = new DataSet();
                DataSet dsTurnos = new DataSet();
                dsProf = prof.ObtenerProfesional(Concatenado);
                string id_profesional = dsProf.Tables["Profesional"].Rows[0][0].ToString();
                string desde = dtDesde.Value.ToString();
                string hasta = dtHasta.Value.ToString();


                ///Aca comparo el Combobox para filtrar por Profesional

                ParameterFieldDefinitions crParameterFieldDefinitions;
                ParameterFieldDefinition crParameterFieldDefinition;
                ParameterValues crParameterValues = new ParameterValues();
                ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();



                crParameterDiscreteValue.Value = id_profesional;
                crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields;
                crParameterFieldDefinition = crParameterFieldDefinitions["Profesional"];

                crParameterValues = crParameterFieldDefinition.CurrentValues;




                crParameterValues.Clear();
                crParameterValues.Add(crParameterDiscreteValue);
                crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);


                /// Aca comparo con el primer DataPicker la fecha desde

                ParameterFieldDefinitions crParameterFieldDefinitions1;
                ParameterFieldDefinition crParameterFieldDefinition1;
                ParameterValues crParameterValues1 = new ParameterValues();
                ParameterDiscreteValue crParameterDiscreteValue1 = new ParameterDiscreteValue();




                crParameterDiscreteValue1.Value = desde;
                crParameterFieldDefinitions1 = rpt.DataDefinition.ParameterFields;
                crParameterFieldDefinition1 = crParameterFieldDefinitions1["Desde"];

                crParameterValues1 = crParameterFieldDefinition1.CurrentValues;


                crParameterValues1.Clear();
                crParameterValues1.Add(crParameterDiscreteValue1);
                crParameterFieldDefinition1.ApplyCurrentValues(crParameterValues1);

                ///Aca comparo el segundo datapicker con la fecha hasta

                ParameterFieldDefinitions crParameterFieldDefinitions2;
                ParameterFieldDefinition crParameterFieldDefinition2;
                ParameterValues crParameterValues2 = new ParameterValues();
                ParameterDiscreteValue crParameterDiscreteValue2 = new ParameterDiscreteValue();


                crParameterDiscreteValue2.Value = hasta;
                crParameterFieldDefinitions2 = rpt.DataDefinition.ParameterFields;
                crParameterFieldDefinition2 = crParameterFieldDefinitions2["Hasta"];

                crParameterValues2 = crParameterFieldDefinition2.CurrentValues;




                crParameterValues2.Clear();
                crParameterValues2.Add(crParameterDiscreteValue2);
                crParameterFieldDefinition2.ApplyCurrentValues(crParameterValues2);



                rpt.SetDatabaseLogon("sa", "ana");
                crystalReportViewer1.ReportSource = rpt;
                crystalReportViewer1.Refresh();
            


        }

    }








        

        
        


    


          

    }

